package com.xmy.cultivate.service.impl;

import com.xmy.cultivate.constants.MqConstants;
import com.xmy.cultivate.entity.RecordCourse;
import com.xmy.cultivate.entity.views.MqCommonDataRs;
import com.xmy.cultivate.respons.QyWeChartPushRs;
import com.xmy.cultivate.service.IMqPushService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MqPushServiceImpl implements IMqPushService {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public boolean pushWechart(String content){
//        try {
//            rabbitTemplate.convertAndSend(MqConstants.EXCHANGE_WECHAR_PUSH_FANOUT, null, content);
//        }catch (Exception e){
//            return false;
//        }
        return true;
    }

    @Override
    public boolean enrollInfoIsTrue(RecordCourse recordCourse){
//        try {
//            rabbitTemplate.convertAndSend(MqConstants.EXCHANGE_ERP_COMMON_DIRECT,MqConstants.KEY_COMMON_6, recordCourse);
//        }catch (Exception e){
//            return false;
//        }
        return true;
    }

    @Override
    public boolean buckleHouse(RecordCourse recordCourse){
//        try {
//            rabbitTemplate.convertAndSend(MqConstants.EXCHANGE_BUCKLE_HOUSE_FANOUT,null, recordCourse);
//        }catch (Exception e){
//            return false;
//        }
        return true;
    }

    /**
     * 推送数据到企业微信
     * @param qyWeChartPushRs
     */
    @Override
    public void pushContentForQyWeChar(QyWeChartPushRs qyWeChartPushRs){
//        try{
//            rabbitTemplate.convertAndSend(MqConstants.EXCHANGE_QY_WECHART_PUSH_MSG_FANOUT, null, qyWeChartPushRs);
//        }catch (Exception e){
//            //System.out.println("out:"+e.getMessage());
//        }
    }


 /*   @Override
    public void pushInterview(Message message){
        try{
            rabbitTemplate.send(MqConstants.DELAY_EXCHANGE, MqConstants.DELAY_ROUTING_KEY, message);
        }catch (Exception e){
            //System.out.println("out:"+e.getMessage());
        }
    }*/

    @Override
    public void pushInterview(MqCommonDataRs mqCommonDataRs, Integer delaySecond){
//        try{
//            Integer delayMillisecond = delaySecond * 1000;//由原来的秒转毫秒
//            rabbitTemplate.convertAndSend(MqConstants.DELAY_EXCHANGE_FANOUT, null, mqCommonDataRs, new MessagePostProcessor() {
//                @Override
//                public Message postProcessMessage(Message message) throws AmqpException {
//                    // 添加延迟消息属性
//                    //message.getMessageProperties().setDelay(1000);//1000为1秒
//                    message.getMessageProperties().setDelay(delayMillisecond);//1000为1秒
//                    return message;
//                }
//            });
//        }catch (Exception e){
//            //System.out.println("out:"+e.getMessage());
//        }
    }

    /**
     *
     * @param mqCommonDataRs
     * @param delaySecond 多少秒后发送数据
     */
    @Override
    public void delayIsLoginAllot(MqCommonDataRs mqCommonDataRs, Integer delaySecond){
//        try{
//            Integer delayMillisecond = delaySecond * 1000;//由原来的秒转毫秒
//            rabbitTemplate.convertAndSend(MqConstants.EXCHANGE_QY_DELAY_FANOUT, null, mqCommonDataRs, new MessagePostProcessor() {
//                @Override
//                public Message postProcessMessage(Message message) throws AmqpException {
//                    // 添加延迟消息属性
//                    //message.getMessageProperties().setDelay(1000);//1000为1秒
//                    message.getMessageProperties().setDelay(delayMillisecond);//1000为1秒
//                    return message;
//                }
//            });
//        }catch (Exception e){
//            //System.out.println("out:"+e.getMessage());
//        }
    }
}
